<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${title }</title>
<!--自定义index样式-->
<link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css"></link>
<link rel="stylesheet" href="${ctx }/static/styles/edit/tableStyle.css"></link>
<!--js库-->
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
<script type="text/javascript" src="${ctx}/static/scripts/WdatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	var headers = {};
	headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
</script>
<style type="text/css">
body{overflow: hidden; padding: 10px 20px;}
#add-cust{position: relative; top: 4px; right: -8px;}
.table-utd select{width: 64px !important;}
.table-utd tbody td:first-child {width: 20px; text-align: center;}
.table-utd tbody td:last-child {width: 40px; text-align: center;}
.table-utd tfoot{display: none;}
#qjy input[type='text']{height: 100%; }
.gasDiv{width:100px; min-height: 26px; border: 0; font-size: 12px;text-align: left;}
.gasDiv input{width:inherit; height:inherit; cursor: pointer;}
.gasDiv label{margin: 2px; display: inline-block; cursor: pointer; min-width: 43px;}
.gasDiv span{width:100%;display:block; text-align:center; line-height: 26px; height: 26px;}
</style>
</head>

<body>
	<form id="editForm" action="${ctx}/bsOrder/save" method="post">
		<input type="hidden" id="billingId" name="p_billingId" value="${obj.billing_id}"></input> 
		<input type="hidden" id="status" name="p_status" value="${obj.status}"></input> 
		<input type="hidden" id="orderId" name="p_orderId" value="${obj.order_id}"></input> 
		<input type="hidden" id="custId" name="p_custId" value="${obj.cust_id}"></input> 
		<input type="hidden" id="billingUser" name="p_billingUser" value="${obj.billing_user}"></input> 
		<input type="hidden" id="serviceUser" name="p_serviceUser" value="${obj.serviceUser}"></input> 
		<table class="table-ltr">
			<tbody>
				<tr>
					<td class="non-empty">用户单位：</td>
					<td style="width: 160px">
						<input type="text" id="customerName" readonly="readonly" value="${obj.customerName}" maxLength="50"></input>
					</td>	
					<td class="non-empty">申请人：</td>
					<td style="width: 160px">${empty obj.billingUserName? LoginUser.userName : obj.billingUserName}</td>
					
					<td class="non-empty">业务员：</td>
					<td>${obj.serviceUserName}</td>
					<td colspan="2" class="td-empty">&nbsp;</td>
				</tr>
				<tr>
					<td class="non-empty">开票名称：</td>
					<c:choose>
						<c:when test="${obj.status==2}">
							<td style="width: 160px"><input type="text" readonly="readonly" id="billingName" placeholder="请输入名称" name="p_billingName" value="${obj.billing_name }" maxLength="50"></input></td>
						</c:when>
						<c:otherwise>
							<td style="width: 160px"><input type="text" id="billingName" placeholder="请输入名称" name="p_billingName" value="${obj.billing_name }" maxLength="50"></input></td>
						</c:otherwise>
					</c:choose>
					
					<td class="non-empty">申请日期：</td>
					<c:choose>
						<c:when test="${obj.status==2}">
							<td style="width: 160px"><input type="text" id="billingDate"  name="p_billingDate" readonly="readonly" value="<fmt:formatDate value="${obj.billing_date}" pattern="yyyy-MM-dd"/>""></input></td>
						</c:when>
						<c:otherwise>
							<td style="width: 160px"><input type="text" id="billingDate" name="p_billingDate"  value="<fmt:formatDate value="${obj.billing_date}" pattern="yyyy-MM-dd"/>" class="Wdate" onFocus="WdatePicker()"></input></td>
						</c:otherwise>
					</c:choose>
					
					<td class="non-empty">总价：</td>
					<td><input type="text" id="totalPrice" readonly="readonly" name="p_totalPrice" value="${empty obj.total_price?'0':obj.total_price}" maxLength="50"></input></td>
					<td colspan="2" class="td-empty">&nbsp;</td>
				</tr>
			</tbody>
		</table>
		<div>
			<table class="table-utd" id="qjy" style="width=100%;">
				<caption>
					开票内容
				</caption>
				<thead>
					<tr>
						<th >序号</th>
						<th class="non-empty">型号</th>
						<th class="non-empty">单价</th>
						<th class="non-empty">数量</th>
					</tr>
				</thead>
				
				<tbody id="tab">
					<c:forEach items="${details}" var="equ" varStatus="detail">
						<tr id="${detail.index}" style="width=100%;">
							<input type="hidden" id="billingDetailId" name="p_billingDetailId" style="text-align:center" value="${equ.billing_detail_id}"></input>
							<td align="center" width="20%">${detail.index+1}</td>
							<td width="35%"><input  id="deviceModel" name="p_deviceModel" readonly="readonly" style="text-align:center" value="${equ.device_model}"></input></td>
							<c:choose>
								<c:when test="${obj.status==2}">
									<td width="20%"><input style="text-align:center" readonly="readonly" class="price" placeholder="请输入单价" min="0" type="number" id="unitPrice" value="${equ.unit_price}" name="p_unitPrice" onkeyup="setTotal()"></input></td>
								</c:when>
								<c:otherwise>
									<td width="20%"><input style="text-align:center" class="price" placeholder="请输入单价" min="0" type="number" id="unitPrice" value="${equ.unit_price}" name="p_unitPrice" onkeyup="setTotal()"></input></td>
								</c:otherwise>
							</c:choose>
							<td width="20%"><input style="text-align:center" readonly="readonly" id="num" class="num" name="p_num" value="${equ.num}"></input></td>
						</tr>
					</c:forEach>
				</tbody>
				
			</table>
		</div>
	</form>
</body>
<script type="text/javascript">
var wh = $(window).height();
var ht = wh - 20 - 161 - 40 - 5;
$('.tab-body').height(ht);

var Index = function(){
	var table, tbody;
	
	//有效性验证
	var requiredValid = function(){
		var pp = parent;
		
		if(!pp.validData("custId","请输入用户单位！"))
			return false; 
			
		if(!pp.validData("billingName","请输入开票名称！"))
			return false;
		if(!pp.validData("billingDate","请选择申请日期！"))
			return false;
		
		var validPrice = true;
		 $("#tab").find("tr").each(function() {  
		        var p = $(this).find('input[class*=price]').val(); 
		        if(p==undefined||p==""){
		        	validPrice = false;
		        }
		   });  
		 
		 if(!validPrice){
			 pp.$.messager.alert('操作提示','请输入单价','warning',function(){
				 	
			 });
			return false;
		 }
		return true;
	};
	
	return {
		init: function(){
			
		},
	
		required: function(){
			return requiredValid();
		}
	};
}();

$(function(){
	Index.init();
});
// 设置总和
function setTotal() {  
    var s = 0;  
    $("#tab").find("tr").each(function() {  
        var t = $(this).find('input[class*=num]').val();  
        var p = $(this).find('input[class*=price]').val(); 
        console.log(t+"====="+p);
        if(p ==""||p.undefined){
        	p = 0;
        }
        s += parseInt(t) * parseFloat(p);  
        console.log(s);
    });  
    $("#totalPrice").val(s.toFixed(2));  
}  
</script>
</html>